

class ReturnCode(object):
    SUCCESS = 0
    FAILED = -100
    UNAUTHORIZED = -500
    BROKEN_AUTHORIZED_DATA = -501
    WRONG_PARAMS = -101
    RESOURCE_NOT_FOUND = -102

    @classmethod
    def message(cls, code):
        if code == cls.SUCCESS:
            return "success"
        elif code == cls.FAILED:
            return "failed"
        elif code == cls.UNAUTHORIZED:
            return "unauthorized"
        elif code == cls.WRONG_PARAMS:
            return "wrong parameters"
        elif code == cls.RESOURCE_NOT_FOUND:
            return "resource not found"
        else:
            return ""


def wrap_json_response(data=None, code=None, message=None):
    ret_response_dict = dict()
    if not code:
        code = ReturnCode.SUCCESS
    if not message:
        message = ReturnCode.message(code)
    if data:
        ret_response_dict["data"] = data
    ret_response_dict["return_code"] = code
    ret_response_dict["message"] = message
    return ret_response_dict


class CommonResponseMixin(object):

    @classmethod
    def wrap_json_response(cls, data=None, code=None, message=None):
        ret_response_dict = dict()
        if not code:
            code = ReturnCode.SUCCESS
        if not message:
            message = ReturnCode.message(code)
        if data:
            ret_response_dict["data"] = data
        ret_response_dict["return_code"] = code
        ret_response_dict["message"] = message
        return ret_response_dict

